/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.edu.upc.dew.sisrest.dao.hibernate;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import pe.edu.upc.dew.sisrest.dao.NoticiaDao;
import pe.edu.upc.dew.sisrest.model.Noticia;

/**
 *
 * @author Aldo
 */
@Repository
public class NoticiaDaoHibernate extends HibernateDaoSupport implements NoticiaDao {

    @Autowired
    public NoticiaDaoHibernate(SessionFactory sessionFactory) {
        setSessionFactory(sessionFactory);
    }

    @Override
    public List<Noticia> obtenerNoticias() {
        List lista = getHibernateTemplate().find("from Noticia");
        return lista;
    }

    @Override
    public Noticia obtenerNoticia(String sId) {
        return (Noticia)getHibernateTemplate().get(Noticia.class, sId);
    }

    @Override
    public void grabarNoticia(Noticia objNot) {
        getHibernateTemplate().saveOrUpdate(objNot);
    }

    @Override
    public void eliminarNoticia(String sId) {
        Noticia oNot = obtenerNoticia(sId);
        getHibernateTemplate().delete(oNot);
    }
}
